<template>
  <div ref="boxwrap" class="YieldCountSecond">
    <div class="time-pick">
      <span>选择月份 </span>
      <el-date-picker
        v-model="month"
        type="month"
        placeholder="选择月份"
      />
    </div>
    <div class="main-content">
      <div class="box-wrap">
        <div class="title">产品良率</div>
        <div class="chart-wrap">
          <topten-line-bar id="topten-percent" height="100%" width="100%" title="前十大不良贡献度" />
        </div>
      </div>
      <div class="box-wrap">
        <div class="chart-wrap">
          <topten-line-bar id="topten-partnum" height="100%" width="100%" title="前十大不良料号" />
        </div>
      </div>
      <div class="box-wrap">
        <div class="title">累计总良率</div>
        <div class="chart-wrap total-yield">
          <div class="gauge-chart">
            <div>
              <gauge id="yield-gauge1" height="100%" width="100%" color="deepskyblue" ctitle="检测数：6520" value="90" />
            </div>
            <div>
              <gauge id="yield-gauge2" height="100%" width="100%" color="deepskyblue" ctitle="检测数：6520" value="80" />
            </div>
          </div>
          <div>
            <line-chart id="unqualified-line" height="100%" width="100%" title="不良率趋势图" />
          </div>
        </div>
      </div>
      <div class="box-wrap">
        <div class="title">前三大不良上升/下降料号</div>
        <div class="chart-wrap rise-fall">
          <div>
            <line-chart id="rise-line" height="100%" width="100%" title="上升料号" />
          </div>
          <div>
            <line-chart id="down-line" height="100%" width="100%" title="下降料号" />
          </div>
        </div>
      </div>
      <div class="box-wrap">
        <div class="title">当天检测料号良率</div>
        <div class="chart-wrap total-yield">
          <div class="gauge-chart">
            <div>
              <gauge id="yield-gauge3" height="100%" width="100%" color="deepskyblue" value="90" />
            </div>
            <div>
              <gauge id="yield-gauge4" height="100%" width="100%" color="deepskyblue" value="80" />
            </div>
          </div>
          <div>
            <rank-bar-line id="rank-bar-line" height="100%" width="100%" title="料号良率排名" />
          </div>
        </div>
        <div ref="tablewrap" class="detail-table">
          <el-table :data="tableDataList" size="medium" border :height="tableHeight" :max-height="tableHeight">
            <el-table-column prop="partNum" label="料号" />
            <el-table-column prop="rate" label="良率" />
            <el-table-column prop="detail" label="明细">
              <!-- 多级表头 -->
              <el-table-column prop="open" label="开路" />
              <el-table-column prop="short" label="短路" />
              <el-table-column prop="gap" label="缺口" />
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ToptenLineBar from './charts/yield/TopTen'
import LineChart from './charts/yield/Line'
import RankBarLine from './charts/yield/BarLine'
import Gauge from './charts/yield/Gauge'

export default {
  name: 'YieldCountSecond',
  components: { ToptenLineBar, LineChart, RankBarLine, Gauge },
  data() {
    return {
      month: '2021-08',
      tableHeight: 'auto',
      tableDataList: []
    }
  },
  mounted() {
    this.getDomStyle()
  },
  created() {
    this.getTableData()
  },
  methods: {
    getDomStyle() {
      const that = this
      const dom = this.$refs.boxwrap
      this.$erd.listenTo(dom, function(element) {
        that.tableHeight = (dom.clientHeight / 2 - 20)
      })
    },
    getTableData() {
      for (let i = 1; i <= 8; i++) {
        this.tableDataList.push({
          partNum: '料号' + i,
          rate: '98%',
          open: 5,
          short: 4,
          gap: 3
        })
      }
    }
  }
}
</script>

<style lang="scss">
.YieldCountSecond{
    width: 100%;
    height: 100%;

    .main-content{
      display: flex;
      flex-wrap: wrap;
      flex-direction: column;
      width: 100%;
      height: calc(100% - 46px);

      .box-wrap{
        width: calc(100% / 3);
        height: 50%;

        &:last-child{
          flex: auto;

          .chart-wrap{
            height: calc(50% - 36px);
          }
          .detail-table{
            height: 50%;
            padding-left: 10px;
          }

        }

        .title{
          margin-left: 20px;
          margin-top: 10px;
          color: #bebebe;
        }

        .chart-wrap{
          height: calc(100% - 30px);
        }

        &:first-child, &:nth-child(3){
          border-bottom: 1px solid #5967a4;
        }
        &:nth-child(3), &:nth-child(4){
          border-left: 1px solid #5967a4;
        }
        &:last-child {
          border-left: 1px solid #5967a4;
        }

        .total-yield{
          > div {
            height: 50%;
          }

            .gauge-chart > div{
              display: inline-block;
              width: 50%;
              height: 100%;
            }
        }

        .rise-fall > div{
          height: 50%;
        }
      }
    }
}
</style>
